#pragma once
#include "shader.hpp"

class heightmap_shader : public shader {
private:
	GLuint _mvpmat_loc;
	GLuint _mvmat_loc;
	GLuint _it_mvmat_loc;

	GLuint _lightdir_loc;
	GLuint _pointlight_pos_loc;
	GLuint _pointlight_color_loc;
	
public:
	bool
	init(const char *vertexfile, const char *fragmentfile) {
		if (!linkprogram(vertexfile, fragmentfile))
			return false;
		_mvpmat_loc = glGetUniformLocation(_program, "u_mvp_matrix");
		_mvmat_loc = glGetUniformLocation(_program, "u_mv_matrix");
		_it_mvmat_loc = glGetUniformLocation(_program, "u_it_mv_matrix");

		_lightdir_loc = glGetUniformLocation(_program, "u_vector2light");
		_pointlight_pos_loc = glGetUniformLocation(_program, "u_pointlight_pos");
		_pointlight_color_loc = glGetUniformLocation(_program, "u_pointlight_color");
		return true;
	}

	void
	setuniform(const glm::mat4 &mvp_mat, const glm::mat4 &mv_mat, const glm::mat4 &it_mv_mat,
			   const float *lightdir, const float *pointlight_pos, const float *pointlight_color) {
		glUniformMatrix4fv(_mvpmat_loc, 1, GL_FALSE, glm::value_ptr(mvp_mat));
		glUniformMatrix4fv(_mvmat_loc, 1, GL_FALSE, glm::value_ptr(mv_mat));
		glUniformMatrix4fv(_it_mvmat_loc, 1, GL_FALSE, glm::value_ptr(it_mv_mat));

		glUniform3fv(_lightdir_loc, 1, lightdir);
		glUniform4fv(_pointlight_pos_loc, 3, pointlight_pos);
		glUniform3fv(_pointlight_color_loc, 3, pointlight_color);
	}
};
